package calorie.com.calorie.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.SPUtils;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.response.UserInfoResponce;
import retrofit2.Call;
import retrofit2.Response;

public class UserInfoContact {
    public static class UserInfoPresent extends BasePresent<IUserInfoView> {
        public void getUserInfo(Context context) {
            try {
                ApiService service = ServiceGenerator.createService(ApiService.class);
                int userId = SPUtils.getInt(Constant.USER_ID, -1, context);
                service.getUserInfo(userId).enqueue(new NetCallBack<UserInfoResponce>() {
                    @Override
                    public void onSuccess(Call<UserInfoResponce> call, Response<UserInfoResponce> response) {
                        if (getView() != null) {
                            getView().getUserInfoData(response);
                        }
                    }

                    @Override
                    public void onFailed() {

                       // ToastUtils.showLongToast(context, "网络请求异常");

                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public interface IUserInfoView extends IBaseView {
        void getUserInfoData(Response<UserInfoResponce> response);


    }
}
